package com.song.tools.log.systemlog.event;

import com.song.tools.log.systemlog.core.SysLogVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

import java.util.List;
import java.util.function.Consumer;

/**
 * 系统日志事件监听
 *
 * @author song tools
 * @since 2024-07-04
 */
@AllArgsConstructor
@Slf4j
public class SysLogEventListener {

    private final List<Consumer<SysLogVo>> consumers;

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void onApplicationEvent(SysLogEvent event) {
        SysLogVo sysLogVo = (SysLogVo) event.getSource();
        for (Consumer<SysLogVo> consumer : consumers) {
            consumer.accept(sysLogVo);
        }
    }
}
